package com.iuie.ns.frame.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class URLUtil {

	private URLUtil() {

	}
	
	private static final Pattern URL_PATTERN = Pattern.compile("^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&amp;%\\$\\-]+)*@)?"
			+ "((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4]"
			+ "[0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}"
			+ "[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]"
			+ "{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]"
			+ "+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\/\\+&amp;%\\$#\\=~_\\-@]*)*$");
	
	/**
	 * 
	 * @desc 验证URL合法性
	 * @author iuie
	 * @date 2017年4月5日 上午8:26:57
	 * @param url
	 * @return
	 */
	public static boolean isValid(String url){
		Matcher matcher = URL_PATTERN.matcher(url);
		return matcher.matches();
	}

}
